<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo2.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="index.html.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="login.html">登陆</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登陆框 -->
        <div class="login-dialog">
            <h3>注册</h3>
            <div class="row">
                <span> 昵称</span>
                <input type="text" id="nickname">
            </div>
            <div class="row">
                <span> 登录名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <div class="row">
                <span>确认密码</span>
                <input type="password" id="password2">
            </div>
            <div class="row">
                <button id="submit" onclick="mySubmit()">提交</button>
            </div>
        </div>
    </div>
<script>
    //进行注册的AJAX
    function mySubmit() {
        var nickname = jQuery("#nickname");
        var username = jQuery("#username");
        var password = jQuery("#password");
        var password2= jQuery("#password2");
        //1 非空判断
        if(jQuery.trim(nickname.val())==""){//去掉空格之后比较
            alert("抱歉，请先输入昵称");
            nickname.focus();//光标重置
            return ;
        }
        if(jQuery.trim(username.val())==""){//去掉空格之后比较
            alert("抱歉，请先输入登录名");
            username.focus();//光标重置
            return ;
        }
        if(jQuery.trim(password.val())==""){//去掉空格之后比较
            alert("抱歉，请先输入密码");
            password.focus();//光标重置
            return ;
        }
        if(jQuery.trim(password2.val())==""){//去掉空格之后比较
            alert("抱歉，请先输入确认密码");
            password2.focus();//光标重置
            return ;
        }
        //这里不需要非空验证，前面已经验过了
        // if(jQuery.trim(password.val()).length<8){
        if(password.val().length < 8){
            alert("密码强度太低，密码数需要大于八位")
            password.focus();
            return;
        }
        if(password.val()!=password2.val()){
            alert("抱歉，两次输入的密码不一致");
            password.focus();
            return;
        }

        //2。通过AJAX发送到后端
        jQuery.ajax({
            url:"reg",
            type:"POST",
            data:{
                "username":username.val(),
                "nickname":nickname.val(),
                "password":password.val()
            },
            success:function(data){
                if(data!=null && data.succ==200){
                    if(data.data ==1){
                        //注册成功
                        alert("恭喜注册成功");
                        //跳转到登录界面
                       // location.href("login.html");
                        location.href="login.html";
                    }else{
                        //注册失败
                        alert("抱歉：注册失败，"+data.msg);
                    }
                }else{
                    alert("后台程序出错");
                }

            }
        });


    }
</script>
</body>

</html>